package com.campusbackend.mapper;

import com.campusbackend.entity.CarouselImage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 轮播图表 Mapper 接口
 * </p>
 *
 * @author yezi
 * @since 2025-07-29
 */
@Mapper
public interface CarouselImageMapper extends BaseMapper<CarouselImage> {

    /**
     * 获取所有轮播图，按位置排序
     * @return 轮播图列表
     */
    @Select("SELECT * FROM carousel_images ORDER BY position ASC")
    List<CarouselImage> getAllCarouselImages();

    /**
     * 获取启用且有图片的轮播图，按位置排序
     * @return 启用的轮播图列表
     */
    @Select("SELECT * FROM carousel_images WHERE is_active = 1 AND image_url IS NOT NULL AND image_url != '' ORDER BY position ASC")
    List<CarouselImage> getActiveCarouselImages();

    /**
     * 根据位置查找轮播图
     * @param position 位置
     * @return 轮播图
     */
    @Select("SELECT * FROM carousel_images WHERE position = #{position}")
    CarouselImage findByPosition(Integer position);
}
